package com.hs.sfzy.util;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.region.Region;
import com.qcloud.cos.transfer.TransferManager;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class COSUtil {
    private static COSClient cosClient = null;
    public static COSClient createCOSClient(){
        String secretID = "AKIDFKEuSmtmQ1OXgb6Yq2SggSzIBFG6nQwL";
        String key = "Y6bTCgwynTvGRREH8oIagaInCUbbNJyS";
        BasicCOSCredentials basicCOSCredentials = new BasicCOSCredentials(secretID, key);
        Region region = new Region("ap-beijing");
        ClientConfig clientConfig = new ClientConfig(region);
        cosClient = new COSClient(basicCOSCredentials, clientConfig);
        return cosClient;
    }

    public static void shutdownCOSClient(){
        if (cosClient != null){
            cosClient.shutdown();
        }
    }

    public static TransferManager createTransferManager(){
        COSClient cosClient1 = createCOSClient();
        ExecutorService threadPool = Executors.newFixedThreadPool(6);
        TransferManager transferManager = new TransferManager(cosClient1, threadPool);
        return transferManager;
    }

    public static void shutdownTransferManager(TransferManager transferManager){
        transferManager.shutdownNow(true);
    }
}
